package com.example.myapplication.adp;

import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.GridLayoutManager;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.example.myapplication.R;
import com.example.myapplication.activity.SellItemDetailAty;
import com.example.myapplication.database.SellItem;
import com.example.myapplication.util.GlideUtil;

import java.util.List;

public class MarketListAdp extends BaseQuickAdapter<SellItem, BaseViewHolder> {
    public MarketListAdp( @Nullable List<SellItem> data) {
        super(R.layout.fgm_market_list_item, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, SellItem item) {
        ImageView itemImg = baseViewHolder.getView(R.id.itemImg);
        GlideUtil.loadImg(item.getPhotos().get(0),itemImg);
        baseViewHolder.setText(R.id.itemTitle,item.getTitle());
        baseViewHolder.setText(R.id.itemDes,item.getDes());
        baseViewHolder.setText(R.id.tvBy,"by "+item.getSellerId());
        baseViewHolder.setText(R.id.itemTag,item.getTag());
        baseViewHolder.setText(R.id.itemPrice,"￥"+item.getPrice());
        GridLayoutManager.LayoutParams params = (GridLayoutManager.LayoutParams) baseViewHolder.itemView.getLayoutParams();
        Log.e("fhp", "convert: "+baseViewHolder.getAdapterPosition() );
        switch ((baseViewHolder.getAdapterPosition()-1)%2){
            case 0:
                params.setMargins(30,0,10,20);
                break;
            case 1:
                params.setMargins(10,0,30,20);

                break;
        }
        baseViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getContext(), SellItemDetailAty.class);
                intent.putExtra("data",item);
                getContext().startActivity(intent);
            }
        });
    }
}
